#include "ObjectPool.h"
#include "ConcurrentAlloc.h"

void TestMultiAlloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 10; i++)
	{
		void* ptr = ConcurrentAlloc(6);
		v.push_back(ptr);
	}

	for (auto e : v)
		ConcurrentFree(e);
}
void TestMultiAlloc2()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 10; i++)
	{
		void* ptr = ConcurrentAlloc(4);
		v.push_back(ptr);
	}

	for (auto e : v)
		ConcurrentFree(e);
}
void TestMultiThread()
{
	std::thread t1(TestMultiAlloc1);

	std::thread t2(TestMultiAlloc2);
	t1.join();
	t2.join();
}

void TestConcurrentAlloc1()
{
	void* p1 = ConcurrentAlloc(1);
	void* p2 = ConcurrentAlloc(5);
	void* p3 = ConcurrentAlloc(7);
	void* p4 = ConcurrentAlloc(1);
	void* p5 = ConcurrentAlloc(6);
	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	cout << p5 << endl;
}
void TestConcurrentAlloc2()
{
	for (size_t i = 0; i < 1024; i++)
	{
		void* p1 = ConcurrentAlloc(1);
	}
	void* p2 = ConcurrentAlloc(1);
}

void TestConcurrentAlloc3()
{
	void* p1 = ConcurrentAlloc(1);
	void* p2 = ConcurrentAlloc(5);
	void* p3 = ConcurrentAlloc(7);
	void* p4 = ConcurrentAlloc(1);
	void* p5 = ConcurrentAlloc(6);
	void* p6 = ConcurrentAlloc(6);
	void* p7 = ConcurrentAlloc(6);
	ConcurrentFree(p1);
	ConcurrentFree(p2);
	ConcurrentFree(p3);
	ConcurrentFree(p4);
	ConcurrentFree(p5);
	ConcurrentFree(p6);
	ConcurrentFree(p7);
}

void BigAlloc()
{
	void* p1 = ConcurrentAlloc(257 * 1024);
	ConcurrentFree(p1);

	void* p2 = ConcurrentAlloc(129 * 8 * 1024);
	ConcurrentFree(p2);
}

//int main()
//{
//	//TestObjectPool();
//	//TLSTest();
//
//	TestConcurrentAlloc3();
//
//	//TestMultiThread();
//
//	BigAlloc();
//
//	return 0;
//}